import { useEffect, useState } from "react";
//替换敏感词
function UseReplaceWord(str:string, words:string[]) {
    const [newStr,setNewStr] = useState('')
    function replaceWord() {
        words.forEach(item => {
            const regexp = new RegExp(item, 'gi')
            str = str.replace(regexp, "*".repeat(item.length))
        })
        console.log('str', str)
        setNewStr(str);
    }

    useEffect(replaceWord,[str, words]
    )
    return newStr;
}

export default UseReplaceWord;